package club.info.redis.repository;

import club.info.redis.pojo.Person;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;


@Repository
public class PersonRepository {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    public void setStr(Person person){
        stringRedisTemplate.opsForValue().set("name",person.getName());
    }

    public String getStr(){
        return stringRedisTemplate.opsForValue().get("name");
    }

    public void setObj(Person person){
        redisTemplate.opsForValue().set(person.getId(),person);
    }

    public Person getObj(Person person){
        return (Person) redisTemplate.opsForValue().get(person.getId());
    }
}
